<template>
<div class="editForm-wrapper">
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading"
             label-width="92px">


            <el-form-item label="车轴类型:" prop="axle"
                :rules="[
                  {required: true, message:'车轴类型不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.axle" placeholder="请填写车轴类型"     ></el-input>
            </el-form-item>

            <el-form-item label="最大载重:" prop="maxGross"
                :rules="[
                  {required: true, message:'最大载重不能为空', trigger:'blur'},
                  {validator: validator.isFloat, trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.maxGross" placeholder="请填写最大载重"     ></el-input>
            </el-form-item>

            <el-form-item label="最小载重:" prop="minGross" style=""
                :rules="[
                  {required: true, message:'最小载重不能为空', trigger:'blur'},
                  {validator: validator.isFloat, trigger:'blur'}
                 ]">
            <el-input v-model="inputForm.minGross" placeholder="请填写最小载重"     ></el-input>
        </el-form-item>
    </el-form>
     <span slot="footer" class="dialog-footer">
       <div class="footer-input">
        <el-button type="primary"  @click="doSubmit()" v-noMoreClick>确定</el-button>
        <el-button @click="visible = false">取消</el-button>
       </div>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          axle: '',
          maxGross: 0,
          minGross: 0
        }
      }
    },
    components: {
    },
    methods: {
    	handleClose(done) {
			this.$Msg.confirm({
				title:'您确定要关闭吗？',
				content:this.GLOBAL.FORM_CLOSE_TIPS,
				confirmCall:()=>{
					done();
				}
			})
		},
      init (method, obj) {
        this.method = method
        if (method === 'add') {
          this.title = `新增车轴类型`
        } else if (method === 'edit') {
          this.title = '修改车轴类型'
          this.inputForm.id = obj.id
        } else if (method === 'view') {
          this.title = '查看车轴类型'
          this.inputForm.id = obj.id
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/truck/truckAxle/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              if (data.success) {
                this.loading = false
                this.inputForm = this.recover(this.inputForm, data.result)
              } else {
                this.loading = false
                this.visible = false
              }
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/truck/truckAxle/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.message)
                this.$emit('refreshDataList')
              }
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>
